// pages/login/login.js
import {getUser} from '../../api/servers'
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  async handleGetUserInfo(e){
    console.log('E',e);
    //获取用户信息
    try{
      const {
        encryptedData,
        rawData,
        iv,
        signature
      }=e.detail;
      //获取小程序登陆后的code
       const {code}=await wx.login();
       console.log('code',code);
       const result=await getUser({
        encryptedData,
        rawData,
        iv,
        signature,
        code
       }).then(res=>{
         console.log('res',res);
         //把token存到缓存中
         wx.setStorageSync('token', res.message)
         wx.navigateBack({
           delta:1
         })
       });
    }catch(e){
      
    }
    
  }
  
})